/*
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

/*
 * @(#)DBMetaClient1.java	1.17 02/01/12
 */

package jdbcts.dbMeta.dbMeta1;

import java.io.*;
import java.util.*;

import java.sql.*;
import javax.sql.*;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.sun.cts.util.*;
import com.sun.cts.porting.*;
import com.sun.cts.harness.*;

import java.rmi.RemoteException;

import javasoft.sqe.javatest.Status;
import jdbcts.SuperTest;
import jdbcts.common.DataSourceConnection;
import jdbcts.common.DriverManagerConnection;
import jdbcts.common.dbSchema;

import com.sun.cts.tests.jdbc.ee.common.*;


// Merant DataSource class
// import com.merant.sequelink.jdbcx.datasource.*;

/**
 * The DBMetaClient1 class tests methods of DatabaseMetaData interface using 
 * Sun's J2EE Reference Implementation.
 * @author  
 * @version 1.7, 06/16/99
 */

public class DBMetaClient1 extends SuperTest implements Serializable 
{
	private static final String testName = "jdbc.ee.dbMeta.dbMeta1";
	
	//Naming specific member variables
	private CTSNamingContextInterface jc = null;

	//Harness requirements 

	private transient static Connection conn = null;
	private transient static DatabaseMetaData dbmd = null;
	private DataSource ds1 = null;
	private static dbSchema dbSch=null;
//	private	String dbName=null,dbUser=null,drManager=null;
	private static String drManager = null;
//	private String sCatalogName=null,sSchemaName=null,sPtable=null,sFtable=null;

	/* Run test in standalone mode */
//	public static void main(String[] args) 
//	{
//		DBMetaClient1 theTests = new DBMetaClient1();
//		Status s=theTests.run(args, System.out, System.err);
//		s.exit();
//	}

	/*
	 *   @class.setup_props: Driver, the Driver name;
	 *                       db1, the database name with url;
	 *                       user1, the database user name;
	 *                       password1, the database password;
	 *                       db2, the database name with url;
	 *                       user2, the database user name;
	 *                       password2, the database password;
	 *                       DriverManager, flag for DriverManager;
	 *                       ptable, the primary table;
	 *                       ftable, the foreign table;
	 *                       cofSize, the initial size of the ptable;
	 *                       cofTypeSize, the initial size of the ftable;
	 *                       binarySize, size of binary data type;
	 *                       varbinarySize, size of varbinary data type;
	 *                       longvarbinarySize, size of longvarbinary data type;
	 *@class.testArgs:     -ap ctssql.stmt
	 */
	@BeforeClass
//	public void setup(String[] args, Properties p) throws Exception 
	public static void setup() throws Exception 
	{
		try
		{
			try
			{
//				drManager = p.getProperty("DriverManager","");
			    drManager = isDRManager;
//				dbName = p.getProperty("db1","");
//				dbUser = p.getProperty("user1","");
//				sPtable = p.getProperty("ptable","CTSTABLE1");
//				sFtable = p.getProperty("ftable","CTSTABLE2");
				if (drManager.length() == 0)
					throw new Exception("Invalid DriverManager Name");
//				if (dbName.length() == 0)
//					throw new Exception("Invalid db1  Database Name");
//				if (dbUser.length() == 0)
//					throw new Exception("Invalid Login Id");
//				if (sPtable.length() == 0)
//					throw new Exception("Invalid Primary table");
//				if (sFtable.length() == 0)
//					throw new Exception("Invalid Foreign table");

//				int nLocdbname = dbName.indexOf('=');
//				sCatalogName = dbName.substring(nLocdbname +1);
//				sCatalogName = sCatalogName.trim();
//				sSchemaName = dbUser;

				if(drManager.equals("yes"))
				{
					logMsg("Using DriverManager");
					DriverManagerConnection dmCon=new DriverManagerConnection();
//					conn = dmCon.getConnection(p);
					conn = dmCon.getConnection(null);
				}
				else 
				{
					logMsg("Using DataSource");
					DataSourceConnection dsCon = new DataSourceConnection();
//					conn = dsCon.getConnection(p);
					conn = dsCon.getConnection(null);
				}
				dbSch = new dbSchema();
//				dbSch.createData(p,conn);
				dbmd=conn.getMetaData();
			}
			catch(SQLException ex)
			{
				logErr("SQL Exception : " + ex.getMessage());
			}
		}
		catch ( Exception e ) 
		{
			logErr("Setup Failed!");
			TestUtil.printStackTrace(e);
		}
	}


	/*
	 * @testName:         testSupportsStoredProcedures
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the
	 *                    DatabaseMetaData interface must be implemented and must behave
	 *                    as specified in the JDBC 1.0 and 2.0 specifications. None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented.(See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The supportsStoredProcedures method must return a boolean value;
	 *                    true if the database supports stored procedure calls and false if 
	 *                    the database does not support it. (See JDK 1.2.2 API  
	 *                    documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase 
	 *                    and call the supportsStoredprocedures() method
	 *                    It should return true value
	 *
	 */
	@Test
	public void testSupportsStoredProcedures() throws Exception
	{
		try
		{
			// invoke on the supportsStoredProcedures
			logMsg("Calling supportsStoredProcedures on DatabaseMetaData");
			boolean retValue=dbmd.supportsStoredProcedures();
			if(retValue)
			{
				logMsg("SupportsStoredProcedures is supported");
			}
			else
			{
				logErr("SupportsStoredProcedures is not supported");
				throw new Exception("supportsStoredProcedures should always return true!");
			}
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to supportsStoredProcedures is Failed!",sqle);
		}	
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to supportsStoredProcedures is Failed!", e);
		}
	}


	/*
	 * @testName:         testAllProceduresAreCallable
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The allProceduresAreCallable method must return a boolean value;
	 *                    true if the user has the security rights of calling all the 
	 *                    procedures returned by the method getProcedures and false 
	 *                    otherwise. (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase 
	 *                    and call the allProceduresAreCallable() method
	 *                    It should return a boolean value
	 *
	 */
	@Test
	public void testAllProceduresAreCallable() throws Exception
	{	
		try
		{
			// invoke on the allProceduresAreCallable
			logMsg("Calling allProceduresAreCallable on DatabaseMetaData");
			boolean retValue=dbmd.allProceduresAreCallable();
			if(retValue)
			{
				logMsg("allProceduresAreCallable method called by the current user");
			}
			else
			{
				logMsg("allProceduresAreCallable method not called by the current user");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to allProceduresAreCallable is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to allProceduresAreCallable is Failed!", e);
		}
	}


	/*
	 * @testName:         testAllTablesAreSelectable
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave 
	 *                    as specified in the JDBC 1.0 and 2.0 specifications. None of the
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The allTablesAreSelectable method must return a boolean value;
	 *                    true if the user can use a SELECT statement with all the 
	 *                    tables returned by the method getTables and false 
	 *                    otherwise. (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase 
	 *                    and call the allTablesAreSelectable() method
	 *                    It should return a boolean value
	 *
	 */
	@Test
	public void testAllTablesAreSelectable() throws Exception
	{
		try
		{
			// invoke on the allTablesAreSelectable
			logMsg("Calling allTablesAreSelectable on DatabaseMetaData");
			boolean retValue=dbmd.allTablesAreSelectable();
			if(retValue)
			{
				logMsg("allTablesAreSelectable method SELECTed by the current user");
			}
			else
			{
				logMsg("allTablesAreSelectable method not SELECTed by the current user");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to allTablesAreSelectable is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to allTablesAreSelectable is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetURL
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave 
	 *                    as specified in the JDBC 1.0 and 2.0 specifications. None of the
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an
	 *                    exception because they are not implemented. (See section 6.2.2.3
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The getURL method must return a String object representing the
	 *                    URL for the database; null if it cannot be generated.
	 *                    (See JDK 1.2.2 API documentation).
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the getURL() method
	 *                    It should return a String or null if it cannot be generated 
	 *
	 */
	@Test
	public void testGetURL() throws Exception
	{	
		try
		{
			// invoke on the getURL
			logMsg("Calling getURL on DatabaseMetaData");
			String sRetValue = dbmd.getURL();
			logTrace("getURL returns null if it cannot be generated");
			if(sRetValue == null)
			{
				logMsg("getURL method return a null value ");
			}
			else
			{
				logMsg("getURL method returns:  " + sRetValue);
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to getURL is Failed!", sqle);
		}
		catch ( Exception e ) 
		{ 
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to getURL is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetUserName
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The getUserName method must return a String object representing 
	 *                    the Username of the database. (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the getUserName() method
	 *                    It should return a String 
	 *
	 */
	@Test
	public void testGetUserName() throws Exception
	{
		try
		{
			// invoke on the getUserName
			logMsg("Calling getUserName on DatabaseMetaData");
			String sRetValue = dbmd.getUserName();
			if( sRetValue == null)
			{
				logMsg("getUserName method does not returns user name ");
			}
			else
			{
				logMsg("getUserName method returns: " + sRetValue);
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to getUserName is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to getUserName is Failed!", e);
		}
	}


	/*
	 * @testName:         testIsReadOnly
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                    
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The isReadOnly method must return a boolean value; true if
	 *                    the database is in read-only mode and false otherwise.
	 *                    (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the isReadOnly() method
	 *                    It should return a boolean value
	 *
	 */
	@Test
	public void testIsReadOnly() throws Exception
	{
		try
		{
			// invoke on the isReadOnly
			logMsg("Calling isReadOnly on DatabaseMetaData");
			boolean retValue=dbmd.isReadOnly();
			if(retValue)
			{
				logMsg("IsReadOnly method is in read-only mode");
			}
			else
			{
				logMsg("IsReadOnly method is not in read-only mode");
			}
		}
		catch (SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to isReadOnly is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to isReadOnly is Failed!", e);
		}
	}


	/*
	 * @testName:         testNullsAreSortedHigh
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The nullsAreSortedHigh method must return a boolean value; 
	 *                    true if NULL values are sorted high and false otherwise.
	 *                    (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the nullsAreSortedHigh() method
	 *                    It should return a boolean value
	 *
	 */
	@Test
	public void testNullsAreSortedHigh() throws Exception
	{
		try
		{
			// invoke on the nullsAreSortedHigh
			logMsg("Calling nullsAreSortedHigh on DatabaseMetaData");
			boolean retValue=dbmd.nullsAreSortedHigh();
			if(retValue)
			{
				logMsg("nullsAreSortedHigh method returns NULL values sorted  high");
			}
			else
			{
				logMsg("nullsAreSortedHigh method returns NULL values not sorted high");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call tp nullsAreSortedHigh is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to nullsAreSortedHigh is Failed!", e);
		}
	}


	/*
	 * @testName:         testNullsAreSortedLow
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The nullsAreSortedLow method must return a boolean value; 
	 *                    true if NULL values are sorted low and false otherwise.
	 *                    (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the nullsAreSortedLow() method
	 *                    It should return a boolean value
	 *
	 */
	@Test
	public void testNullsAreSortedLow() throws Exception
	{
		try
		{
			// invoke on the nullsAreSortedLow
			logMsg("Calling nullsAreSortedLow on DatabaseMetaData");
			boolean retValue=dbmd.nullsAreSortedLow();
			if(retValue)
			{
				logMsg("nullsAreSortedLow method returns NULL values sorted low");
			}
			else
			{
				logMsg("nullsAreSortedLow method returns NULL values not sorted low");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to nullsAreSortedLow is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to nullsAreSortedLow is Failed!", e);
		}
	}


	/*
	 * @testName:         testNullsAreSortedAtStart
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                    
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The nullsAreSortedAtStart method must return a boolean value; 
	 *                    true if NULL values are sorted at the start regardless of the
	 *                    sort order and false otherwise. (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the nullsAreSortedAtStart() method
	 *                    It should return a boolean value
	 *
	 */
	@Test
	public void testNullsAreSortedAtStart() throws Exception
	{
		try
		{
			// invoke on the nullsAreSortedAtStart
			logMsg("Calling nullsAreSortedAtStart on DatabaseMetaData");
			boolean retValue=dbmd.nullsAreSortedAtStart();
			if(retValue)
			{
				logMsg("nullsAreSortedAtStart method returns NULL values sorted at the start");
			}
			else
			{
				logMsg("nullsAreSortedAtStart method returns NULL values not sorted at the start");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to nullsAreSortedAtStart is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to nullsAreSortedAtStart is Failed!", e);
		}
	}


	/*
	 * @testName:         testNullsAreSortedAtEnd
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The nullsAreSortedAtEnd method must return a boolean value; 
	 *                    true if NULL values are sorted at the end regardless of the
	 *                    sort order and false otherwise. (See JDK 1.2.2 API documentation)	 
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the nullsAreSortedAtEnd() method
	 *                    It should return a boolean value
	 *
	 */
	@Test
	public void testNullsAreSortedAtEnd() throws Exception
	{
		try
		{
			// invoke on the nullsAreSortedAtStart
			logMsg("Calling NullsAreSortedAtEnd on DatabaseMetaData");
			boolean retValue=dbmd.nullsAreSortedAtEnd();
			if(retValue)
			{
				logMsg("nullsAreSortedAtEnd method returns NULL values sorted at the end");
			}
			else
			{
				logMsg("nullsAreSortedAtEnd method returns NULL values not sorted at the end");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to nullsAreSortedAtEnd is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to nullsAreSortedAtEnd is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetDatabaseProductName
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                    
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The getDatabaseProductName method must return a String object 
	 *                    (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the getDatabaseProductName() method
	 *                    It should return a String 
	 *
	 */
	@Test
	public void testGetDatabaseProductName() throws Exception
	{	
		try
		{
			// invoke on the getDatabaseProductName
			logMsg("Calling getDatabaseProductName on DatabaseMetaData");
			String sRetValue =dbmd.getDatabaseProductName();
			if(sRetValue == null)
			{
				logMsg("getDatabaseProductName method does not returns database product name ");
			}
			else
			{
				logMsg("getDatabaseProductName method returns:  " + sRetValue);
			}
			
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to getDatabaseProductName is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to getDatabaseProductName is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetDatabaseProductVersion
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The getDatabaseProductVersion method must return a String object 
	 *                    (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the getDatabaseProductVersion() method
	 *                    It should return a String 
	 *
	 */
	@Test
	public void testGetDatabaseProductVersion() throws Exception
	{	
		try
		{
			// invoke on the getDatabaseProductVersion
			logMsg("Calling getDatabaseProductVersion on DatabaseMetaData");
			String sRetValue = dbmd.getDatabaseProductVersion();
			if(sRetValue == null)
			{
				logMsg("getDatabaseProductVersion  method does not returns a database product version ");
			}
			else
			{
				logMsg("getDatabaseProductVersion method returns:  " + sRetValue);
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to getDatabaseProductVersion is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to getDatabaseProductVersion is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetDriverName
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The getDriverName method must return a String object 
	 *                    (See JDK 1.2.2 API documentation) 
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the getDriverName() method
	 *                    It should return a String 
	 *
	 */
	@Test
	public void testGetDriverName() throws Exception
	{
		try
		{
			// invoke on the getDriverName
			logMsg("Calling getDriverName on DatabaseMetaData");
			String sRetValue = dbmd.getDriverName();
			if(sRetValue == null)
			{
				logMsg("getDriverName method does not returns a JDBC Driver Name ");
			}
			else
			{
				logMsg("getDriverName method returns:  " + sRetValue);
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to getDriverName is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to getDriverName is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetDriverVersion
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The getDriverVersion method must return a String object 
	 *                    representing the driver version including its major and minor
	 *                    version numbers. (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the getDriverVersion() method
	 *                    It should return a String 
	 *
	 */
	@Test
	public void testGetDriverVersion() throws Exception
	{
		try
		{
			// invoke on the getDriverVersion
			logMsg("Calling getDriverVersion on DatabaseMetaData");
			String sRetValue = dbmd.getDriverVersion();
			if(sRetValue == null)
			{
				logMsg("getDriverVersion method does not returns a Driver Version ");
			}
			else
			{
				logMsg("getDriverVersion returns:  " + sRetValue);
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to getDriverVersion is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to getDriverVersion is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetDriverMajorVersion
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The getDriverMajorVersion method must return a integer value 
	 *                    representing the driver major version. (See JDK 1.2.2 API 
	 *                    documentation) 
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the getDriverMajorVersion() method
	 *                    It should return a Integer value 
	 *
	 */
	@Test
	public void testGetDriverMajorVersion() throws Exception
	{
		try
		{
			// invoke on the getDriverMajorVersion
			logMsg("Calling getDriverMajorVersion on DatabaseMetaData");
			int drMajorVersion=dbmd.getDriverMajorVersion();
			if(drMajorVersion>=0)
			{
				logMsg("getDriverMajorVersion method returns: " + drMajorVersion);
			}
			else
			{
				logMsg(" getDriverMajorVersion method returns a negative value" );
			}
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to getDriverMajorVersion is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetDriverMinorVersion
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The getDriverMinorVersion method must return a integer value 
	 *                    representing the driver major version. (See JDK 1.2.2 API 
	 *                    documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the getDriverMinorVersion() method
	 *                    It should return a Integer value 
	 *
	 */
	@Test
	public void testGetDriverMinorVersion() throws Exception
	{
		try
		{
			// invoke on the getDriverMinorVersion
			logMsg("Calling getDriverMinorVersion on DatabaseMetaData");
			int drMinorVersion=dbmd.getDriverMinorVersion();
			if(drMinorVersion>=0)
			{
				logMsg(" getDriverMinorVersion method returns: " + drMinorVersion);
			}
			else
			{
				logMsg(" getDriverMinorVersion method returns a negative value: " + drMinorVersion);
			}
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to getDriverMinorVersion Failed!", e);
		}
	}


	/*
	 * @testName:         testUsesLocalFilePerTable
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The usesLocalFilePerTable method must return a boolean value; 
	 *                    true if the database uses a local file for each table.
	 *                    (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the usesLocalFilePerTable() method
	 *                    It should return a boolean value
	 *
	 */
	@Test
	public void testUsesLocalFilePerTable() throws Exception
	{
		try
		{
			// invoke on the usesLocalFilePerTable
			logMsg("Calling usesLocalFilePerTable on DatabaseMetaData");
			boolean retValue=dbmd.usesLocalFilePerTable();
			if(retValue)
			{
				logMsg("usesLocalFilePerTable method returns database uses a local file");
			}
			else
			{
				logMsg("usesLocalFilePerTable method returns database not uses a local file");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exception " + sqle.getMessage() );
			throw new Exception("Call to usesLocalFilePerTable is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to usesLocalFilePerTable Failed!", e);
		}
	}


	/*
	 * @testName:         testSupportsMixedCaseIdentifiers
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The supportsMixedCaseIdentifiers method must return a boolean 
	 *                    value; true if DBMS allows mixed case SQL Identifiers in SQL
	 *                    statements as case-sensitive and false otherwise.  A JDBC 
	 *                    compliant driver will  always return false. 
	 *                    (See JDK 1.2.2 API documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the supportsMixedCaseIdentifiers() method
	 *                    It should return a boolean value
	 *
	 */
	@Test
	public void testSupportsMixedCaseIdentifiers() throws Exception
	{
		try
		{
			// invoke on the supportsMixedCaseIdentifiers
			logMsg("Calling supportsMixedCaseIdentifiers on DatabaseMetaData");
			boolean retValue=dbmd.supportsMixedCaseIdentifiers();
			if(retValue)
			{
				logMsg("supportsMixedCaseIdentifiers method is supported");
			}
			else
			{
				logMsg("supportsMixedCaseIdentifiers method is not supported");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exceptions " + sqle.getMessage() );
			throw new Exception("Call to supportsMixedCaseIdentifiers is Failed!", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to supportsMixedCaseIdentifiers Failed!", e);
		}
	}


	/*
	 * @testName:         testStoresUpperCaseIdentifiers
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The storesUpperCaseIdentifiers method must return a boolean 
	 *                    value; true if DBMS allows mixed case SQL Identifiers in SQL
	 *                    statements as case-insensitive and stores them as all uppercases
	 *                    in its metadata tables and false otherwise. (See JDK 1.2.2 API 
	 *                    documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the storesUpperCaseIdentifiers() method
	 *                    It should return a boolean value
	 *
	 */
	@Test
	public void testStoresUpperCaseIdentifiers() throws Exception
	{
		try
		{
			// invoke on the storesUpperCaseIdentifiers
			logMsg("Calling storesUpperCaseIdentifiers on DatabaseMetaData");
			boolean retValue=dbmd.storesUpperCaseIdentifiers();
			if(retValue)
			{
				logMsg("storesUpperCaseIdentifiers method returns unquoted SQL identifiers stored as upper case");
			}
			else
			{
				logMsg("storesUpperCaseIdentifiers method returns unquoted SQL identifiers not stored as upper case");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exceptions " + sqle.getMessage() );
			throw new Exception("Call to storesUpperCaseIdentifiers is Failed", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to storesUpperCaseIdentifiers is Failed!", e);
		}
	}


	/*
	 * @testName:         testStoresLowerCaseIdentifiers
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    
	 *                    The storesLowerCaseIdentifiers method must return a boolean 
	 *                    value; true if DBMS allows mixed case SQL Identifiers in SQL
	 *                    statements as case-insensitive and stores them as all lowercases
	 *                    in its metadata tables and false otherwise. (See JDK 1.2.2 API 
	 *                    documentation)
	 *                    
	 * @test_Strategy:    Get the DataBaseMetaData object from the Connection to the DataBase
	 *                    and call the storesLowerCaseIdentifiers() method
	 *                    It should return a boolean value
	 *
	 */
	@Test
	public void testStoresLowerCaseIdentifiers() throws Exception
	{
		try
		{
			// invoke on the storesLowerCaseIdentifiers
			logMsg("Calling storesLowerCaseIdentifiers on DatabaseMetaData");
			boolean retValue=dbmd.storesLowerCaseIdentifiers();
			if(retValue)
			{
				logMsg("storesLowerCaseIdentifiers method returns unquoted SQL identifiers stored as lower case");
			}
			else
			{
				logMsg("storesLowerCaseIdentifiers returns unquoted SQL identifiers not stored as lower case");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL exceptions " + sqle.getMessage() );
			throw new Exception("Call to storesLowerCaseIdentifiers is Failed", sqle);
		}
		catch ( Exception e )
		{
			logErr("Unexpected exception " + e.getMessage() );
			throw new Exception("Call to storesLowerCaseIdentifiers Failed!", e);
		}
	}


	/* cleanup */
	@AfterClass
	public static void  cleanup() throws Exception
	{
		try
		{
			// Close the database 
//			dbSch.destroyData(conn);
			dbSch.dbUnConnect(conn);
			logMsg("Cleanup ok;");
		}
		catch (Exception e)
		{
			logErr("An error occurred while closing the database connection");
		}
	}
}
